package com.gao.d_selector.f;

/**
 * @author gao
 * @time 2020/08/13 22:30:08
 */
public class Utils {
    public static byte[] intToByte(int n) {
        byte[] bb = new byte[4];
        bb[0] = (byte) (n >>> 24);
        bb[1] = (byte) (n >>> 16) ;
        bb[2] = (byte) (n >>> 8) ;
        bb[3] = (byte) (n >>> 0) ;
        return bb;
    }

    public static int byteToInt(byte[] bb) {
        int n = 0;
        // bb[0] & 255，是把byte类型转换为int类型，然后再进行左移操作
        n |= (bb[0] & 255) << 24;
        n |= (bb[1] & 255) << 16;
        n |= (bb[2] & 255) << 8;
        n |= (bb[3] & 255) << 0;
        return n;
    }
}
